<?

function smarty_function_select( $params, $smarty ) {

	$smarty->depend( 'modifier', 'escape' );

	$from = $params['from'];
	$id = $params['id'];
	$name = Smutty_Smarty::getFieldName( $params['name'] );
	$text = $params['text'] ? $params['text'] : 'name';
	$value = $params['value'] ? $params['value'] : 'id';
	$selected = $params['selected'] ? $params['selected'] : false;

	// add a label?
	if ( $label = $params['label'] ) {
		$smarty->depend( 'function', 'label' );
		smarty_function_label(array(
			'for' => $params['name'],
			text => $label
		), $smarty );
	}

	echo '<select name="' . $name . '" id="' . $id . '">' .
		'<option value=""></option>';

	foreach ( $from as $obj )
		echo '<option value="' . $obj->$value . '"' .
			( $obj->$value == $selected ? ' selected="selected"' : '' ) .
			'>' .
			smarty_modifier_escape($obj->$text) .
		'</option>';

	echo '</select>';

}

?>